package myoar

object Drone {

  import de.yadrone.base.ARDrone

  trait WantedState {
    def run(drone:ARDrone):Unit
  }

  object States {

    def toSpeed(angle:Double):Int = (angle * 100).toInt

    import Myo.Angles
    case class Tilting(angles:Angles) extends WantedState {
      def run(drone:ARDrone) = {
        drone.move3D(
          toSpeed(angles.x),
          toSpeed(angles.y),
          0,
          toSpeed(angles.z))
      }
    }
    case class ChangingAltitude(angle:Double) extends WantedState {
      def run(drone:ARDrone) = {
        drone.move3D(
          0,
          0,
          toSpeed(angle),
          0)
      }
    }

    trait CategoricalState extends WantedState
    object Hovering extends CategoricalState {
      override val toString = "Hovering"
      def run(drone:ARDrone) = drone.hover
    }
    object Landing extends CategoricalState {
      override val toString = "Landing"
      def run(drone:ARDrone) = drone.landing
    }
    object TakingOff extends CategoricalState {
      override val toString = "TakingOff"
      def run(drone:ARDrone) = drone.takeOff
    }
    object HaltingMotors extends CategoricalState {
      override val toString = "HaltingMotors"
      def run(drone:ARDrone) = drone.reset
    }
  }

  val ip = "192.168.1.1" // default in YADrone. making it explicit
  val drone:ARDrone = new ARDrone(ip)

  def init = drone.start

}
